import axios from 'axios';

import {
  
    CHANGE_BANNERS,
    CHANGE_RECOMMEND,
    FETCH_HOME_MULTIDATA
} from './constants.js';



//请求的数据 轮播图和推荐的action
export const changeBannerAction = (banners) => ({
    type: CHANGE_BANNERS,
    banners
})

export const changeRecommendAction = (recommends) => ({
    type: CHANGE_RECOMMEND,
    recommends
}) 


//redux-thunk中定义的action函数
export const getHomeMultidataAction = dispatch => {
    axios({
        url: 'http://123.207.32.32:8000/home/multidata',

    }).then(res => {
        const data = res.data.data;
        dispatch(changeBannerAction(data.banner.list));
        dispatch(changeRecommendAction(data.recommend.list));

    })
}

//redux-saga拦截的action
export const fetchHomeMultidataAction = {
    type: FETCH_HOME_MULTIDATA
}